package com.typhoon.extend.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/index")
public class IndexController extends BaseController {

    @RequestMapping(value = "/hello.do")
    public void sayHello(HttpServletRequest request, HttpServletResponse response) {
        Map<String,Object> result = new HashMap<>();
        result.put("name","typhoon");
        this.putSuccessResult(response,result);
    }
    
    @RequestMapping("/hellofm.do")
    public String helloFreeMarker(Model model) {
        model.addAttribute("name","Typhoon博客");  
        return "hellofm.ftl";
    }
    
    @RequestMapping(value = "/login.do")  
    public ModelAndView login() {  
        ModelAndView mav = new ModelAndView("index");  
        mav.addObject("username", "typhoon");  
        mav.addObject("projectName", "extendDemo");  
        return mav;//ModelAndView mav = new ModelAndView("redirect:/index.do");index.do里面再返回视图可以重定向解决表单重复提交  
    } 
    

    @RequestMapping(value = "/tologin.do")
    public ModelAndView  toLogin(HttpServletRequest request, HttpServletResponse response) {
    	 ModelAndView mv = new ModelAndView();
    	 mv.setViewName("login");
    	return mv;
    }
    
    @RequestMapping(value="/register-forward.do")
    public String toRegister(HttpServletRequest request, HttpServletResponse response) {
    	return "register";
    }
    
    @RequestMapping(value="/no-permission.do")
    public String unAuth(HttpServletRequest request, HttpServletResponse response) {
    	return "error/403";
    }

}